/*
 * WinderMatrixTest.cpp
 *
 * Copyright 2012 Fabian Wenzelmann
 *
 * This file is part of Recognition-Procedures-for-Boolean-Functions.
 *
 * Recognition-Procedures-for-Boolean-Functions is free software: you
 * can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * Recognition-Procedures-for-Boolean-Functions is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Recognition-Procedures-for-Boolean-Functions.
 *
 * If not, see <http://www.gnu.org/licenses/>.
 */

#include <iostream>
#include <fstream>

#include <gtest/gtest.h>

#include "bfr/DIMACSParser.hpp"
#include "bfr/ClauseSet.hpp"
#include "bfr/WinderMatrix.hpp"

namespace bfr { namespace test {

TEST(WinderMatrix, create_and_swaprows) {
    DIMACSParser parser;
    std::ifstream in;
    in.open("test_files/WinderMatrixTest.dnf");
    ClauseSet *cs = parser.parse(in);
    WinderMatrix wm(cs);
    in.close();

    size_t expected[5][5] = {{1, 0, 0, 0, 0},
                         {0, 3, 0, 0, 0},
                         {0, 3, 0, 0, 0},
                         {0, 2, 0, 0, 0},
                         {0, 2, 0, 0, 0}};

    for (size_t i = 0; i < wm.size(); i++) {
        for (size_t j = 0; j < wm.size(); j++) {
            size_t e = expected[i][j];
            size_t c = wm[i][j];
            EXPECT_EQ(e, c);
        }
    }

    wm.swapRows(0, 1);
    wm.swapRows(2, 4);
    size_t expected2[5][5] = {{0, 3, 0, 0, 0},
                         {1, 0, 0, 0, 0},
                         {0, 2, 0, 0, 0},
                         {0, 2, 0, 0, 0},
                         {0, 3, 0, 0, 0}};

    for (size_t i = 0; i < wm.size(); i++) {
        for (size_t j = 0; j < wm.size(); j++) {
            size_t e = expected2[i][j];
            size_t c = wm[i][j];
            EXPECT_EQ(e, c);
        }
    }

}

} // namespace test
} // namespace bfr
